package com.example.application.views.study;

import com.example.application.views.main.MainView;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.html.Anchor;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.H1;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.QueryParameters;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.router.RouteConfiguration;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Route(value = "one",layout = MainView.class)
@PageTitle("页面一")
public class OneView extends Div {

   public OneView(){

       H1 h1 = new H1("页面一");

       //使用超链接的导航
      // Anchor anchor = new Anchor("two","跳转到页面二");
       //创建一个按钮
       Button button = new Button("跳转到页面二");

       TextField name = new TextField();
       TextField gender = new TextField();
       TextField age = new TextField();

       HorizontalLayout layout = new HorizontalLayout(name,gender,age);

       button.addClickListener((event)->{
           //服务端进行页面的跳转
          // UI.getCurrent().navigate("two");
           //无参数
          //UI.getCurrent().navigate(TwoView.class);
           //过时了
          // UI.getCurrent().navigate(TwoView.class,"10");
           //对于具有必需参数的导航目标，该参数将提供给解析器，返回字符串包含该参数。
          // String url = RouteConfiguration.forSessionScope().getUrl(TwoView.class,"10");

       //使用查询字符串的方式
          /* Map<String, List<String>> parms = new HashMap<>();
           List<String> nameList = new ArrayList<>();
           nameList.add(name.getValue());
           parms.put("name",nameList);
           List<String> genderList = new ArrayList<>();
           genderList.add(gender.getValue());
           parms.put("gender",genderList);
           List<Map<String, List<String>>> list = new ArrayList<>();
           list.add(parms);
           QueryParameters queryParameters = new QueryParameters(parms);

           UI.getCurrent().navigate("two",queryParameters);*/

          // String url = RouteConfiguration.forSessionScope().getUrl(TwoView.class,id.getValue());
        //restFul
        /*List<String> parms = new ArrayList<String>();
           parms.add(name.getValue());
           parms.add(gender.getValue());
           parms.add(age.getValue());*/
      // String url = RouteConfiguration.forSessionScope().getUrl(TwoView.class,parms);

           //System.out.println(url);

           //UI.getCurrent().navigate(url);



       });

       this.add(h1,button,layout);
       //this.add(anchor);
   }
}
